package com.ybxx.hr.service.impl;

import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.ybxx.core.command.QueryFilter;
import com.ybxx.core.dao.GenericDao;
import com.ybxx.core.service.impl.BaseServiceImpl;
import com.ybxx.core.web.paging.PagingBean;
import com.ybxx.hr.dao.HrUserDao;
import com.ybxx.hr.model.HrUser;
import com.ybxx.hr.service.HrUserService;

public class HrUserServiceImpl extends BaseServiceImpl<HrUser> implements
		HrUserService {
	private HrUserDao userDao;
	public HrUserServiceImpl(HrUserDao dao) {
		super(dao);
		this.userDao=dao;
		// TODO Auto-generated constructor stub
	}
	public List<HrUser> queryPage(HrUser hrUser,QueryFilter filter) {
		String hql="from HrUser hr";
		String condition=" where ";
		if(hrUser!=null && StringUtils.isNotEmpty(hrUser.getName())){
			hql+=condition+" hr.name='"+hrUser.getName()+"' ";
			condition=" and ";
		}
		if(hrUser!=null && hrUser.getWorkContent()!=null && StringUtils.isNotEmpty(hrUser.getWorkContent().getWcid())){
			hql+=condition+"hr.workContent.wcid='"+hrUser.getWorkContent().getWcid()+"'";
			condition=" and ";
		}
		if(hrUser!=null && hrUser.getWork()!=null && StringUtils.isNotEmpty(hrUser.getWork().getWid())){
			hql+=condition+"hr.work.wid='"+hrUser.getWork().getWid()+"'";
			condition=" and ";
		}
		if(hrUser!=null && hrUser.getDept()!=null && StringUtils.isNotEmpty(hrUser.getDept().getDid())){
			hql+=condition+"hr.dept.did='"+hrUser.getDept().getDid()+"'";
		}
		return userDao.findByHql(hql, null,filter.getPagingBean());
	}
	public List<HrUser> queryConditionExportExcel(HrUser hrUser){
		String hql="from HrUser hr left join fetch hr.dept " +
				"left join fetch hr.school " +
				"left join fetch hr.work " +
				"left join fetch hr.workContent " +
				"left join fetch hr.workType";
		String condition=" where ";
		if(hrUser!=null && StringUtils.isNotEmpty(hrUser.getName())){
			hql+=condition+" hr.name='"+hrUser.getName()+"' ";
			condition=" and ";
		}
		if(hrUser!=null && hrUser.getWorkContent()!=null && StringUtils.isNotEmpty(hrUser.getWorkContent().getWcid())){
			hql+=condition+"hr.workContent.wcid='"+hrUser.getWorkContent().getWcid()+"'";
			condition=" and ";
		}
		if(hrUser!=null && hrUser.getWork()!=null && StringUtils.isNotEmpty(hrUser.getWork().getWid())){
			hql+=condition+"hr.work.wid='"+hrUser.getWork().getWid()+"'";
			condition=" and ";
		}
		if(hrUser!=null && hrUser.getDept()!=null && StringUtils.isNotEmpty(hrUser.getDept().getDid())){
			hql+=condition+"hr.dept.did='"+hrUser.getDept().getDid()+"'";
		}
		return userDao.findByHql(hql, null);
	}

}
